/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ventanas;

import java.awt.Color;
import java.io.File;
import java.util.Date;
import javax.swing.JFileChooser;

/**
 *
 * @author b3f0
 */
public class VAgregarCliente extends javax.swing.JFrame {

    /**
     * Creates new form VAgregarCliente
     */
    public VAgregarCliente() {
        initComponents();
        iniciardatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jLabel2 = new javax.swing.JLabel();
        tNombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tApellido = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tDireccion = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tTelefono = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tCelular = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tDNI = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tObraSocial = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        tProfesion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        tFNacimiento = new javax.swing.JFormattedTextField();
        jLabel10 = new javax.swing.JLabel();
        tCMedico = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        tEmail = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        tWeb = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        tFacebook = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        tTwitter = new javax.swing.JTextField();
        cActivo = new javax.swing.JCheckBox();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tDetalle = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setText("Nombre:");

        tNombre.setText("Pablo Javier");

        jLabel3.setText("Apellido:");

        tApellido.setText("Heurtley");

        jLabel4.setText("Direccion:");

        tDireccion.setText("Calle 497 n° 765");

        jLabel5.setText("Telefono:");

        tTelefono.setText("0223-4675919");

        jLabel6.setText("Celular:");

        tCelular.setText("2235370053");

        jLabel7.setText("DNI:");

        tDNI.setText("32944789");

        jLabel8.setText("Obra Social");

        tObraSocial.setText("Medife");

        jLabel1.setText("Profesion:");

        tProfesion.setText("Consultor");

        jLabel9.setText("F. Nacimiento:");

        tFNacimiento.setText("jFormattedTextField1");

        jLabel10.setText("Cert. Medico:");

        tCMedico.setText("jFormattedTextField2");

        jLabel11.setText("Email:");

        tEmail.setText("pablo@hcomputacion.com");

        jLabel12.setText("Web:");

        tWeb.setText("www.hcomputacion.com");

        jLabel13.setText("Facebook:");

        tFacebook.setText("pheurtley");

        jLabel14.setText("Twitter:");

        tTwitter.setText("pheurley");

        cActivo.setSelected(true);
        cActivo.setText("Activo");

        jLabel15.setText("Detalle:");

        tDetalle.setColumns(20);
        tDetalle.setRows(5);
        jScrollPane1.setViewportView(tDetalle);

        jButton1.setText("Agregar Cliente");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(36, 36, 36)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel5)
                                .addComponent(jLabel4)
                                .addComponent(jLabel6)
                                .addComponent(jLabel7)
                                .addComponent(jLabel8)
                                .addComponent(jLabel1)
                                .addComponent(jLabel9)
                                .addComponent(jLabel10)
                                .addComponent(jLabel11)
                                .addComponent(jLabel12)
                                .addComponent(jLabel13)
                                .addComponent(jLabel14)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel3))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tDireccion)
                    .addComponent(tTelefono)
                    .addComponent(tCelular)
                    .addComponent(tDNI)
                    .addComponent(tObraSocial)
                    .addComponent(tProfesion)
                    .addComponent(tFNacimiento)
                    .addComponent(tApellido)
                    .addComponent(tCMedico)
                    .addComponent(tEmail)
                    .addComponent(tWeb)
                    .addComponent(tFacebook)
                    .addComponent(tTwitter)
                    .addComponent(cActivo)
                    .addComponent(tNombre))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(67, 67, 67)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(tNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(tApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(tDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(tTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(tCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(tDNI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(tObraSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(tProfesion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(tFNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(tCMedico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(tEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(tWeb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(tFacebook, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel14)
                            .addComponent(tTwitter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(cActivo)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        agregarfoto();
        verificardatos();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VAgregarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VAgregarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VAgregarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VAgregarCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VAgregarCliente().setVisible(true);
            }
        });
    }
    public void iniciardatos()
    {
        tFNacimiento.setValue(fnacimiento);
        tCMedico.setValue(cmedico);
    }
    public void verificardatos()
    {
        boolean todook = false;
        if (cActivo.isSelected()==true)
        {
            System.out.println("El cliente Agregado esta marcado como activo");
            activo = "A";
        }else
        {
            System.out.println("El cliente Agregado esta marcado como INactivo!!");
            activo = "I";
        }
        if ("".equals(tNombre.getText()))
        {
            System.out.println("Faltan datos por llenar");
            tNombre.setBackground(Color.red);
            todook=false;
        }
        if ("".equals(tApellido.getText()))
        {
            tApellido.setBackground(Color.red);
            todook=false;
        }
        if ("".equals(tDNI.getText()))
        {
            tDNI.setBackground(Color.red);
            todook=false;
        }
        if ("".equals(tCelular.getText()))
        {
            tCelular.setBackground(Color.red);
            todook=false;
        }
        if ("".equals(tEmail.getText()))
        {
            tEmail.setBackground(Color.red);
            todook=false;
        }
        if (fnacimiento.equals(tFNacimiento.getValue()))
        {
            tFNacimiento.setBackground(Color.red);
            todook=false;
        }
        if (todook = true)    
        {
            System.out.println("Datos basicos verificados. OK!");
            agregardatos();
        }
        else
        {
            System.out.println("Faltan datos por llenar");
        }
            
    }
    public void agregardatos()
    {
        finscripcion = new Date();
        abm.agregar(tNombre.getText(), tApellido.getText(), tDireccion.getText(), tTelefono.getText(), tCelular.getText(), tDNI.getText(), tObraSocial.getText(), tProfesion.getText(), fnacimiento, finscripcion, cmedico, "M", tEmail.getText(), tWeb.getText(), tFacebook.getText(), tTwitter.getText(), tDetalle.getText(), activo, status, foto);
    }
    
    public void agregarfoto()
    {
        JFileChooser fc = new JFileChooser();
        int resp = fc.showOpenDialog(this);
        if(resp == JFileChooser.APPROVE_OPTION){
        foto = fc.getSelectedFile();
        dirarchivo = foto.getAbsolutePath();
}
    }
    
    Date fnacimiento = new Date();
    Date cmedico = new Date();
    Date finscripcion = new Date();
    clases.ABMClientes abm = new clases.ABMClientes();
    String activo = "A";
    String status = "P";
    File foto;
    String dirarchivo = "";
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cActivo;
    private javax.swing.JButton jButton1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField tApellido;
    private javax.swing.JFormattedTextField tCMedico;
    private javax.swing.JTextField tCelular;
    private javax.swing.JTextField tDNI;
    private javax.swing.JTextArea tDetalle;
    private javax.swing.JTextField tDireccion;
    private javax.swing.JTextField tEmail;
    private javax.swing.JFormattedTextField tFNacimiento;
    private javax.swing.JTextField tFacebook;
    private javax.swing.JTextField tNombre;
    private javax.swing.JTextField tObraSocial;
    private javax.swing.JTextField tProfesion;
    private javax.swing.JTextField tTelefono;
    private javax.swing.JTextField tTwitter;
    private javax.swing.JTextField tWeb;
    // End of variables declaration//GEN-END:variables
}
